﻿using System;
using System.Web.UI;
using Entity;
using BLL;
using BLL.Access;
using System.Data;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class YUETIAOZXX : BasePage
    {
        #region 属性

        #endregion

        #region 变量
        /// <summary>
        /// 访问数据库
        /// </summary>
        SpHelper _sphelper = new SpHelper();
        /// <summary>
        /// 来函信息
        /// </summary>
        YS_LH_LAIHANXXProcess bllh = new YS_LH_LAIHANXXProcess();
        /// <summary>
        /// 月调整
        /// </summary>
        YS_LH_YUETIAOZProcess bllyue = new YS_LH_YUETIAOZProcess();
        /// <summary>
        /// 上传
        /// </summary>
        SYS_UPLOADProcess bllupload = new SYS_UPLOADProcess();
        /// <summary>
        /// 用户信息
        /// </summary>
        YS_YG_YONGHUXXProcess bllyhxx = new YS_YG_YONGHUXXProcess();
        /// <summary>
        /// 流程
        /// </summary>
        YS_LH_LAIHANLCJLBLL lcbll = new YS_LH_LAIHANLCJLBLL();
        /// <summary>
        /// 日志
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        /// <summary>
        /// 来函保存用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess laihanyhxx = new YS_LH_YONGHUXXProcess();
        #endregion

        #region 事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }
        protected override void OnLoadComplete(EventArgs e)
        {
            //对需要加载页上的所有其他控件的任务使用该事件。
            if (!IsPostBack)
            {
                BindData();
                SetControlStatus(); 
            }

        }
        #endregion

        #region 方法
        private void BindData()
        {
            string laihanbh = Request["laihanbh"];
            string yonghubh = Request["yonghubh"];
            int laihanid = Convert.ToInt32(Request["id"]);

            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANBH", "ROLEID", null, string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];
            string zhandian = dtZhanDian.Rows[0]["TEXT"].ToString();//站点
            string roleid = dtZhanDian.Rows[0]["VALUE"].ToString();//9001 业务员，3001 办事处主任
            /*
            if (string.IsNullOrEmpty(Request["laihanbh"]) && string.IsNullOrEmpty(Request["yonghubh"])&&int.TryParse(Request["id"],out laihanid))
            {
                return;
            }
            */
            YS_LH_LAIHANXX lh = bllh.SelectYS_LH_LAIHANXX(laihanid);

            if (lh != null)
            {
                
                laihanbh = lh.S_LAIHANBH;
                yonghubh = lh.S_YONGHUBH;
            }
           

            //string where = string.Format(" S_LAIHANBH='{0}' ",laihanbh);

            //DataTable lhable = bllh.SelectYS_LH_LAIHANXXesDynamic(where, " ID desc", null);
            //if (lhable == null)
            //{
            //    return;
            //}
            //string id = lhable.Rows[0]["ID"].ToString();
            //YS_LH_LAIHANXX lh = bllh.SelectYS_LH_LAIHANXX(Convert.ToInt32(id));
            UCLHUserInfo.LoadInfo(lh);
            this.UCLHLCSHENPIYIJIANS.LoadInfo(lh);

            if (lh == null)
            {
                return;
            }
            /* comment by guodengjie
            //UCLHUserInfo.YONGHUH = lh.S_YONGHUBH;
            //UCLHUserInfo.YONGHUHINPUT = lh.S_YONGHUBH;
            //UCLHUserInfo.XUKEBH = lh.S_XUKEBH;
            //UCLHUserInfo.TONGYIBM = lh.S_TONGYIBM;
            //UCLHUserInfo.LAIHANBH = lh.S_LAIHANBH;
            //UCLHUserInfo.GUANLIKBH = lh.S_GUANLIKBH;
            //UCLHUserInfo.ZHANDIANBH = lh.S_ZHANDIANBH;
             * */
            txtLY.Text = lh.S_SHENQINGLY;


            /*comment by guodengjie
            DataTable userdt = laihanyhxx.SelectYS_LH_YONGHUXXesDynamic(string.Format(" S_YONGHUBH='{0}' and S_LAIHANBH='{1}'", lh.S_YONGHUBH, lh.S_LAIHANBH), "", null);
            if (userdt != null && userdt.Rows.Count > 0)
            {
                UCLHUserInfo.YONGHUM = userdt.Rows[0]["S_YONGHUM"].ToString();
                UCLHUserInfo.DIZHI = userdt.Rows[0]["S_DIZHI"].ToString();

                UCLHUserInfo.LIANXIBM = userdt.Rows[0]["S_LIANXIBM"].ToString();

                UCLHUserInfo.YOUBIAN = userdt.Rows[0]["S_YOUBIAN"].ToString();
                UCLHUserInfo.LIANXIR = userdt.Rows[0]["S_LIANXIR"].ToString();
                UCLHUserInfo.LIANXIDH = userdt.Rows[0]["S_LIANXIDH"].ToString();
            }
            */
            DataTable yuetz = bllyue.SelectYS_LH_YUETIAOZsDynamic(string.Format("S_LAIHANBH='{0}'", lh.S_LAIHANBH), "  ID desc", null);
            if (yuetz != null && yuetz.Rows.Count > 0)
            {
                /*
                UCLHUserInfo.Y = yuetz.Rows[0]["I_Y"].ToString();
                UCLHUserInfo.M = yuetz.Rows[0]["I_M"].ToString();
                 * */
                txtYongHuSQL.Text = yuetz.Rows[0]["I_SHENQINGL"].ToString();
                this.txtYJH.Text = Convert.ToString(yuetz.Rows[0]["I_JH_Y"]);
                this.txtSYSYSL.Text = Convert.ToString(yuetz.Rows[0]["I_SYL_SY"]);
                if (roleid == "9001")
                {
                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    //txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    //txtcz.Text = yuetz.Rows[0]["S_CHUZHANG"].ToString();
                    txtCZSHL.Text = yuetz.Rows[0]["I_CHUZHANG"].ToString();
                }
                else if (roleid == "3001")
                {
                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    //txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    txtZHURENSHL.Text = yuetz.Rows[0]["I_ZHUREN"].ToString();
                    //txtZR.Text = yuetz.Rows[0]["S_ZHUREN"].ToString();
                }
                else if (roleid == "2001")
                {
                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    //txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    txtZHURENSHL.Text = yuetz.Rows[0]["I_ZHUREN"].ToString();
                    //txtZR.Text = yuetz.Rows[0]["S_ZHUREN"].ToString();

                    txtJSKSHL.Text = yuetz.Rows[0]["I_JIESHUIKZ"].ToString();
                    //txtJS.Text = yuetz.Rows[0]["S_JIESHUIKZ"].ToString();
                }
                else if (roleid == "2003")
                {
                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    //txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    txtZHURENSHL.Text = yuetz.Rows[0]["I_ZHUREN"].ToString();
                    //txtZR.Text = yuetz.Rows[0]["S_ZHUREN"].ToString();

                    txtJSKSHL.Text = yuetz.Rows[0]["I_JIESHUIKZ"].ToString();
                    //txtJS.Text = yuetz.Rows[0]["S_JIESHUIKZ"].ToString();

                    txtJCKSHL.Text = yuetz.Rows[0]["I_JICAIKZ"].ToString();
                    //txtJC.Text = yuetz.Rows[0]["S_JICAIKZ"].ToString();
                }
                else if (roleid == "1001")
                {

                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    txtZHURENSHL.Text = yuetz.Rows[0]["I_ZHUREN"].ToString();
                    txtJSKSHL.Text = yuetz.Rows[0]["I_JIESHUIKZ"].ToString();

                    txtJCKSHL.Text = yuetz.Rows[0]["I_JICAIKZ"].ToString();
                    txtCZSHL.Text = yuetz.Rows[0]["I_CHUZHANG"].ToString();

                    ////txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    ////txtZR.Text = yuetz.Rows[0]["S_ZHUREN"].ToString();
                    ////txtJS.Text = yuetz.Rows[0]["S_JIESHUIKZ"].ToString();

                    ////txtJC.Text = yuetz.Rows[0]["S_JICAIKZ"].ToString();
                    ////txtcz.Text = yuetz.Rows[0]["S_CHUZHANG"].ToString();
                }
                else if (Convert.ToInt32(roleid) > 9001)
                {
                    txtYEWUYJYL.Text = yuetz.Rows[0]["I_YEWUYJY"].ToString();
                    txtZHURENSHL.Text = yuetz.Rows[0]["I_ZHUREN"].ToString();
                    txtJSKSHL.Text = yuetz.Rows[0]["I_JIESHUIKZ"].ToString();

                    txtJCKSHL.Text = yuetz.Rows[0]["I_JICAIKZ"].ToString();
                    txtCZSHL.Text = yuetz.Rows[0]["I_CHUZHANG"].ToString();

                    //txtYWY.Text = yuetz.Rows[0]["S_YEWUYJY"].ToString();

                    //txtZR.Text = yuetz.Rows[0]["S_ZHUREN"].ToString();
                    //txtJS.Text = yuetz.Rows[0]["S_JIESHUIKZ"].ToString();

                    //txtJC.Text = yuetz.Rows[0]["S_JICAIKZ"].ToString();
                    //txtcz.Text = yuetz.Rows[0]["S_CHUZHANG"].ToString();
                }
                /*
                int y = Convert.ToInt32(UCLHUserInfo.Y);
                int m = Convert.ToInt32(UCLHUserInfo.M);
                if (m == 1)
                {
                    y = y - 1;
                    m = 12;
                }
                else
                {
                    m = m - 1;
                }
                DataSet ds = _sphelper.P_YS_LH_YONGHUYSSJCX(y, m, lh.S_YONGHUBH.Trim(), null);
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    try
                    {
                        int YJH = Convert.ToInt32(ds.Tables[0].Rows[0]["I_YUANJIHUA"]);
                        int SYL = Convert.ToInt32(ds.Tables[0].Rows[0]["I_SHIYONGSL"]);
                        txtYJH.Text = (YJH).ToString();
                        txtSYSYSL.Text = (SYL).ToString();

                       
                    }
                    catch (Exception ex)
                    {
                        PageTools.AlertMsg(this, ex.Message);
                    }

                }
                 * */
            }
           
            

        }
        private void SetControlStatus()
        {
           
            foreach (Control c in form1.Controls)
            {
                
                if (c is DevExpress.Web.ASPxMemo )
                {
                    DevExpress.Web.ASPxMemo t = c as DevExpress.Web.ASPxMemo;
                    t.ReadOnly = true;
                }
                if ( c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox t = c as DevExpress.Web.ASPxTextBox;
                    t.ReadOnly = true;
                }
            }
            foreach (Control c in UCLHUserInfo.Controls)
            {

                if (c is DevExpress.Web.ASPxMemo)
                {
                    DevExpress.Web.ASPxMemo t = c as DevExpress.Web.ASPxMemo;
                    t.ReadOnly = true;
                }
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox t = c as DevExpress.Web.ASPxTextBox;
                    t.ReadOnly = true;
                }
            }
        }
        #endregion
    }
}